package com.zqxq.lottery.entity.o2o.user;

import com.zqxq.lottery.entity.po.user.UserAddressPO;
import com.zqxq.lottery.entity.vo.user.UserAddressVO;
import org.springframework.util.StringUtils;

public class UserAddressO2O {

    public static UserAddressVO toVO(UserAddressPO po) {
        if (po == null) {
            return null;
        }
        UserAddressVO userAddressVO = new UserAddressVO();
        userAddressVO.setId(String.valueOf(po.getId()));
        userAddressVO.setUserId(String.valueOf(po.getUser_id()));
        userAddressVO.setReceiverName(po.getReceiver_name());
        userAddressVO.setPhoneNumber(po.getPhone_number());
        userAddressVO.setProvince(po.getProvince());
        userAddressVO.setCity(po.getCity());
        userAddressVO.setCounty(po.getCounty());
        userAddressVO.setStreet(po.getStreet());
        userAddressVO.setDetailAddress(po.getDetail_address());
        return userAddressVO;
    }

    public static UserAddressPO toPO(UserAddressVO vo) {
        if (vo == null) {
            return null;
        }
        UserAddressPO userAddressPO = new UserAddressPO();
        if(!StringUtils.isEmpty(vo.getId())){
            userAddressPO.setId(Long.valueOf(vo.getId()));
        }
        if(!StringUtils.isEmpty(vo.getUserId())){
            userAddressPO.setUser_id(Long.valueOf(vo.getUserId()));
        }
        userAddressPO.setReceiver_name(vo.getReceiverName());
        userAddressPO.setPhone_number(vo.getPhoneNumber());
        userAddressPO.setProvince(vo.getProvince());
        userAddressPO.setCity(vo.getCity());
        userAddressPO.setCounty(vo.getCounty());
        userAddressPO.setStreet(vo.getStreet());
        userAddressPO.setDetail_address(vo.getDetailAddress());
        return userAddressPO;
    }
}
